<?php
defined ( 'BASEPATH' ) or exit ( 'No direct script access allowed' );
class Project_content_model extends MY_Model {
	public function __construct() {
		parent::__construct ( 'project_content' );
	}
	/**
	 * 创建数据表
	 */
	public function create() {
		$this->drop ();
		$sql = "CREATE TABLE `project_content` (
				  `pcid` int(10) unsigned NOT NULL AUTO_INCREMENT COMMENT '众创项目内容id',
				  `pid` int(10) unsigned NOT NULL COMMENT '众创项目id',
				  `content` text NOT NULL COMMENT '众创项目内容',
				  `type` tinyint(1) unsigned NOT NULL DEFAULT '0' COMMENT '众创项目内容类别（0：文字；1：图片）',
				  `sort` int(10) unsigned NOT NULL COMMENT '内容排序',
				  `check` tinyint(1) unsigned NOT NULL DEFAULT '1' COMMENT '众创项目审核状态（1：未审核；2：审核不通过；3：审核通过）',
				  `status` tinyint(1) unsigned NOT NULL DEFAULT '1' COMMENT '众创项目状态（0：删除；1：正常）',
				  PRIMARY KEY (`pcid`)
				) ENGINE=InnoDB AUTO_INCREMENT=1000 DEFAULT CHARSET=utf8 COMMENT='众创项目内容关联表';";
		$re = $this->db->simple_query ( $sql );
	}
	/**
	 * 删除数据表
	 */
	public function drop() {
		$sql = 'DROP TABLE IF EXISTS `project_content`;';
		$re = $this->db->simple_query ( $sql );
		return $re;
	}
	/**
	 * 查询并返回一条数据
	 * $whereArr:(array)查询的条件
	 * $type:返回结果类型，默认为obj格式，arr为数组格式
	 * return:查询结果
	 */
	public function row_order($whereArr,$orderby = "") {
		$this->db->where ( $whereArr );
		if (! empty ( $orderby )) {
			$orderby = str_replace ( "@", " ", $orderby );
			$this->db->order_by ( $orderby );
		}
		$query = $this->db->get ( $this->table );
		return $query->row_array ();
	}
}